﻿//功能描述：绩效管理：部门内考核
using Hong.IRepository.IRepository_AssessmentManagement;
using Hong.Model.SysDomain.Model_AssessmentManagement.ViewDepErsonnel;
using Hong.Model.SysDomain.Model_SystemSettings;
using Hong.Repository.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hong.Repository.Repository.Repository_AssessmentManagement
{
    public class AssDepRepository: IAssDepRepository
    {
        #region 构造器注入
        private readonly T_HongShi_3Context _dal;
        public AssDepRepository(T_HongShi_3Context dal)
        {
            _dal = dal;
        }
        #endregion
        #region 部门考核

        #region 显示
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<Department> GetDepartment()
        {
            var list = _dal.Departments.ToList();
            return list;
        }
        #endregion

        #region 显示人员设置
        /// <summary>
        /// 显示人员设置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<ViewDepErsonnels> GetViewDepErsonnels(int? id)
        {
            var list1 = _dal.Departments.ToList();
            var list2= _dal.Personnel.ToList();
            var query = from a in list1
                        join b in list2 on a.DepId equals b.DepartmentId
                        select new ViewDepErsonnels
                        {
                            DepId = a.DepId,
                            DepType = a.DepType,
                            DepDescribe = a.DepDescribe,
                            DepSort = a.DepSort,
                            DepSuperior = a.DepSuperior,
                            DepHide = a.DepHide,
                            DepName = a.DepName,
                            PersonnelId = b.PersonnelId,
                            PersonnelName = b.PersonnelName,
                            PersonnelUserName = b.PersonnelUserName,
                            PersonneIpassword = b.PersonneIpassword,
                            PersonneIbir = b.PersonneIbir,
                            PersonneIsix = b.PersonneIsix,
                            PersonneImajor = b.PersonneImajor,
                            DepartmentId = b.DepartmentId,
                            PersonneIroleId = b.PersonneIroleId,
                            PersonneImailbox = b.PersonneImailbox,
                            PersonneIphone = b.PersonneIphone,
                            PersonneIcontact = b.PersonneIcontact,
                            DesignTitle = b.DesignTitle,
                            Mposition = b.Mposition,
                            TechnicalPosition = b.TechnicalPosition,
                            Subjection = b.Subjection,
                            JobStatus = b.JobStatus,
                            EntryTime = b.EntryTime,
                            HeadPortrait = b.HeadPortrait,
                            PersonneIsort = b.PersonneIsort,
                            DepartureTime = b.DepartureTime
                        };
            if (id != null)
            {
                query = query.Where(x => x.DepId == id);

            }
            return query.ToList();
        }
        #endregion

        #region 设置考核状态
        public int PutDepartment(int id)
        {
            var obj = _dal.Departments.FirstOrDefault(x=>x.DepId==id);
            obj.DepHide = true;
            var i= _dal.SaveChanges();
            return i;
        }
        #endregion
        #endregion
    }
}
